<template>
  <div class="container">
    <topTitle
      :titleText="titleText"
      :back="true"
      @gobackTriser="goBack"
    ></topTitle>
    <div class="mainCon">
      <div class="info complainInfo">
        <p class="title">
          {{ infoDetail.compName }}<span>({{ infoDetail.uscc }})</span>
        </p>
        <el-row>
          <el-col>
            <el-row>
              <el-col :span="12" class="desc"
                >风险事件：{{ infoDetail.riskEvent }}</el-col
              >
              <el-col :span="12" class="desc"
                >风险等级：{{ infoDetail.riskLevel }}</el-col
              >
            </el-row>
          </el-col>
          <el-col>
            <el-row>
              <el-col :span="12" class="desc"
                >{{ typeDesc }}时间：{{ infoDetail.riskTime }}</el-col
              >
              <el-col :span="12" class="desc"
                >{{ typeDesc }}天数：{{ infoDetail.dayNum }}</el-col
              >
            </el-row>
          </el-col>
          <el-col>
            <el-row>
              <el-col :span="12" class="desc"
                >{{ typeDesc }}原因：{{ infoDetail.riskReason }}</el-col
              >
              <el-col :span="12" v-if="type === 'ALERT'" class="desc"
                >当前状态：{{ infoDetail.status }}</el-col
              >
            </el-row>
          </el-col>
        </el-row>
        <el-row>
          <el-col v-if="type === 'ALERT'" class="desc"
            >{{ typeDesc }}原因明细：{{ infoDetail.punishReason }}</el-col
          >
          <el-col v-else class="desc warningDesc">
            <el-row>{{ typeDesc }}原因明细：</el-row>
            <el-row
              v-if="
                infoDetail.riskEvent === '用水异常' ||
                infoDetail.riskEvent === '用电异常' ||
                infoDetail.riskEvent === '纳税异常'
              "
            >
              <el-col :span="8" class="desc"
                >异常年月：{{ infoDetail.punishTime }}</el-col
              >
              <el-col :span="8" class="desc"
                >异常原因：{{ infoDetail.punishReason }}</el-col
              >
            </el-row>
            <el-row v-else>
              <el-col :span="8" class="desc"
                >列入日期：{{ infoDetail.punishTime }}</el-col
              >
              <el-col :span="8" class="desc"
                >列入机关：{{ infoDetail.punishOrgan }}</el-col
              >
              <el-col :span="8" class="desc"
                >列入原因：{{ infoDetail.punishReason }}</el-col
              >
            </el-row>
          </el-col>
        </el-row>
      </div>
      <div class="info progressInfo">
        <p class="title">
          {{ type === 'ALERT' ? '预警风险' : '警示风险' }}办理记录
        </p>
        <div v-for="v in progressDetail" :key="v.id" class="infoBox">
          <div class="subBox">
            <span class="subTitle">系统</span>
            {{ v.handleTime | transformTimestamp }}
          </div>
          <div class="subProgress">
            <template v-if="v.dataSource === '1'">
              <p>添加进展：{{ v.progress }}</p>
              <p v-if="type === 'ALERT'">办理状态：{{ v.handleStatus }}</p>
            </template>
            <template v-else>
              <p>{{ v.progress }}</p>
            </template>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'warningRiskDetail',
  data() {
    return {
      titleText: '企业风险详情',
      type: '',
      typeDesc: '',
      infoDetail: {},
      progressDetail: [],
      statusEnum: {
        PROCESSING: '处理中',
        ELIMINATE: '已消除',
        COMPLETED: '已办结',
      },
    }
  },
  async mounted() {
    const { id, type } = this.$route.query
    this.type = type
    if (type === 'ALERT') {
      this.typeDesc = '预警'
    } else {
      this.typeDesc = '警示'
    }
    await this.getInfoDetail(id)
  },
  filterField: {
    //时间转换
    transformTimestamp(timestamp) {
      let date = new Date(timestamp)
      const Y = date.getFullYear() + '年'
      const M =
        (date.getMonth() + 1 < 10
          ? '0' + (date.getMonth() + 1)
          : date.getMonth() + 1) + '月'
      const D =
        (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + '日  '
      const h =
        (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':'
      const m =
        (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) +
        ':'
      const s =
        date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
      const dateString = Y + M + D + h + m + s
      return dateString
    },
  },
  methods: {
    // 详情
    getInfoDetail(id) {
      return this.axios({
        method: 'post',
        url: 'api-p/companyrisk/base/detail',
        data: {
          id,
        },
      })
        .then((response) => {
          if (!response.data.hasError) {
            this.infoDetail = response.data.result
            this.progressDetail = response.data.result.riskHandleList || []
          } else {
            this.$message.error(response.data.errorMsg)
          }
        })
        .catch((error) => {
          if (error.response) {
            this.$message.error(error.response.data)
          }
        })
    },
    //返回
    goBack() {
      this.$router.push('/home/enterpriseRiskManagement/riskManagement')
      this.$store.commit('GOBACK_NAME', {
        oldUrl: '/home/enterpriseRiskManagement/riskManagement',
        newUrl: this.$router.currentRoute.fullPath,
      })
    },
  },
}
</script>

<style lang="less" scoped>
.container {
  .mainCon {
    height: calc(100% - 67px);
    overflow-y: auto;
    padding: 24px;
    background: #f5f7fa;
    .info {
      padding: 30px 24px;
      background: #fff;
      .title {
        font: bold 18px Microsoft YaHei;
        color: #333333;
        span {
          font-size: 16px;
          margin-left: 20px;
        }
      }
      .desc {
        margin-top: 40px;
        line-height: 20px;
      }
      .warningDesc {
        padding: 24px;
        background-color: #f2f2f2;
      }
      .infoBox {
        margin-top: 20px;
        border-top: solid 1px #999;
        .subBox {
          margin-top: 20px;
          .subTitle {
            font: bold 18px Microsoft YaHei;
            line-height: 30px;
            margin-right: 40px;
            padding-left: 14px;
            position: relative;
            &::before {
              content: '';
              display: block;
              position: absolute;
              top: 7px;
              left: 0px;
              width: 8px;
              height: 8px;
              background: #009588;
              border-radius: 50%;
            }
          }
        }
        .subProgress {
          margin-top: 10px;
          padding-left: 16px;
        }
        p {
          line-height: 28px;
        }
      }
    }
    .progressInfo {
      min-height: 200px;
      margin-top: 20px;
    }
  }
}
</style>
